package com.yzy.service;

import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzy.entity.Goods;
import com.yzy.entity.query.WrappedGood;
import com.yzy.mapper.GoodsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsService extends ServiceImpl<GoodsMapper, Goods>{
    @Resource
    private GoodsMapper goodsMapper;

    @Deprecated
    public List<Goods> search_(String key){

        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.like("name",key);
        return list(wrapper);

    }
    /**
     * @description 重新设计返回商品的接口，将文件类型包装进入返回的接口数据中
     * @param key 关键字
     * @return java.util.List<com.yzy.entity.query.WrappedGood>
     * @author mgl
     * @date 2023/8/10 22:05
     */
    public List<WrappedGood> search(String key) {
        return goodsMapper.search(key);
    }

    /**
     * @description 查询商品详情
     * @param goodsId 商品id
     * @return com.yzy.entity.query.WrappedGood
     * @author mgl
     * @date 2023/8/12 11:53
     */
    public WrappedGood details(Integer goodsId) {
        return goodsMapper.details(goodsId);
    }

    /**
     * @description 查询用户创建的商品，对应我的上传
     * @param userId 用户id
     * @return java.util.List<com.yzy.entity.Goods>
     * @author mgl
     * @date 2023/8/12 11:53
     */
    public List<Goods> mine(Integer userId) {
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.eq("upload_user_id",userId);
        return list(wrapper);
    }
}
